package yijianbao.API;


import com.alibaba.fastjson.JSONObject;
import com.aventstack.extentreports.ExtentTest;
import org.apache.http.HttpResponse;
import org.apache.http.impl.client.CloseableHttpClient;
import yijianbao.Utils.FileWrite;
import yijianbao.Utils.ReadExcel;
import yijianbao.http.RequestAPI;
import yijianbao.listener.ExtentTestNGITestListener;
import yijianbao.listener.WriteInfo;

import java.util.HashMap;

public class YJBAPI extends RequestAPI {
    RequestAPI client = new RequestAPI();
    WriteInfo writeinfo = new WriteInfo();
    FileWrite fw = new FileWrite();
    ReadExcel re = new ReadExcel();
    JSONObject responseBody;
    int responseCode;
    static String url = null;
    static String session = null;
    String token = null;
    String sid = null;
    String msg =null;
    CloseableHttpClient httpclient;
    HttpResponse res;
    String time = null;
    ExtentTestNGITestListener el = new ExtentTestNGITestListener();
    ExtentTest log = el.getlog();


    HashMap<String, String> responseHeads;
    public void addGooods() throws Exception {

//        CloseableHttpClient closeableHttpClient = HttpClients.createDefault();
//        String url="https://drug.fanyuns.com/web/index.php?s=api/cart/" +
//                "add&goods_id=2455&goods_sku_id=0&wxapp_id=47&token=671df9f39b127999c389c513e96cf749&source=2&weliamv=1026&edition=ind";
//        HttpGet get = new HttpGet(url);
//        CloseableHttpResponse response;
//        try {
//            response = closeableHttpClient.execute(get);
//           System.out.println("hhhhhh"+HttpsRequest.get("https://www.alipay.com"));
//            System.out.println(EntityUtils.toString(response.getEntity(), "utf-8").toString());

//        } catch (ClientProtocolException e) {
//            // TODO Auto-generated catch block
//            e.printStackTrace();
//        } catch (IOException e) {
//            // TODO Auto-generated catch block
//            e.printStackTrace();
//        }




//        String regurl = yijianbao.Constants.InterfaceConstants.HOST + "/login/byAccount?token=&sid=&";
//        String regurl = QXQ.Constants.InterfaceConstants.HOST +"/login/byAccount?token=&oh=89AE65C40257482E6F9FC7C4E843B96A_1603096438856_21efe6d3f6d1f1e9&sid=&_s=33AF8F6C789D6EF6CD134D5891E919D5C27B1BE7&_t=1603096438859";
        String regurl = "https://shop.newoffen.net/web/index.php?s=api/cart/add&goods_id=2455&goods_sku_id=0&wxapp_id=47&token=671df9f39b127999c389c513e96cf749&source=2&weliamv=1026&edition=ind";
//        String regurl = "https://passport.jd.com/loginservice.aspx?method=Login&callback=jsonpLogin&_=1618896474254";

        long timestamp = System.currentTimeMillis();//获取系统当前时间戳
        String body_string = "{\"platformInfo\": {\"fid\": 689999,\"maxClick\": \"56623\",\"release\": \"2020090310\",\"pid\": \"89AE65C40257482E6F9FC7C4E843B96A\",\"imsi\": \"89AE65C40257482E6F9FC7C4E843B96A\",\"ua\": \"\",\"versionName\": \"5.6.4\",\"systemVersion\": \"9\",\"mac\": \"B4:0F:B3:7E:A4:A3\",\"platform\": \"3\",\"baseType\": \"roseLive\",\"phonetype\": \"vivo_vivo Z1\",\"operators\": -1,\"mobileIP\": \"192.168.130.162\",\"product\": \"9\",\"netType\": 2,\"h\": 2201,\"version\": \"5.6.4\",\"versionCode\": \"1001\",\"yyCode\": \"a9559709c0a6ed74eaace7ab431e83f2\",\"version2\": \"40050604\",\"w\": 1080,\"imei\": \"862226043685179\",\"packName\": \"com.meigui.mgxq\",\"did\": \"DuV3pstKI05lWtPthv7K5mAu3yOgxtFNJr/8B08yBCb+ULZgsl1KJFAmeqfz7uQmR9BIWdCX3uZUM2146VUr678g\"},\"userName\": \"1048490712\",\"password\": \"123456\"}";

        //拼接完整URL请求
//        url = client.requestHeaderInHash(timestamp, regurl);


        //传参发送post请求并接收reponse data
        time = writeinfo.getTime();
//        res = client.http_post(url, body_string);
        res = client.http_get(regurl);
        System.out.println("res66666!"+res);

//        try{
//            res = client.http_get(regurl);
//            System.out.println("res66666!"+res);
//        }catch(Exception e){
//            System.out.println("Wrong!");
//        }

        responseBody = client.getBodyInJSON();
        responseCode = client.getCodeInNumber();
        responseHeads = client.getHeaderInHash();

        //获取msg
//        msg = responseBody.getJSONObject("msg").getString("userId");
        msg = responseBody.getString("msg");

//        String fromChannel = responseBody.getJSONObject("userInfo").getString("fid");
//        System.out.println("sid"+sid);
        log.info("msg:" + msg);
//        System.out.println("sid:" + sid);

        //获取登录token
//        token = responseBody.getString("token");
    }
}
